package com.wit.witmg.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wit.witmg.entity.TProdFee;
import com.wit.witmg.mapper.TProdFeeMapper;
import com.wit.witmg.service.ITProdFeeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wit.witmg.util.JsonResult;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bob
 * @since 2025-01-20
 */
@Service
public class TProdFeeServiceImpl extends ServiceImpl<TProdFeeMapper, TProdFee> implements ITProdFeeService {

    @Override
    public Object get(HttpServletRequest request, String date1, String date2) {
        //开始日期date1，结束日期date2;筛选两个日期之间的数据，并将pcwg、tldepr、depr、rt、ec、ep分别累加返回；
        QueryWrapper<TProdFee> qw=new QueryWrapper<>();
        qw.between("indate",date1,date2);
        List<TProdFee> list=list(qw);
        double pcwg=0;
        double tldepr=0;
        double depr=0;
        double rt=0;
        double ec=0;
        double ep=0;
        if(!list.isEmpty()){
            for (TProdFee t:list) {
                pcwg+=t.getPcwg();
                tldepr+=t.getTldepr();
                depr+=t.getDepr();
                rt+=t.getRt();
                ec+=t.getEc();
                ep+=t.getEp();
            }
        }
        JSONObject object=new JSONObject();
        object.put("pcwg",pcwg);
        object.put("tldepr",tldepr);
        object.put("depr",depr);
        object.put("rt",rt);
        object.put("ec",ec);
        object.put("ep",ep);
        return JsonResult.success(object);
    }
}
